package com.deltapunkt.proxy.main;

import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import com.deltapunkt.proxy.AsyncServer;
import com.deltapunkt.proxy.TaskScheduler;
import com.deltapunkt.proxy.factory.ProxyFactory;
import com.deltapunkt.proxy.factory.Settings;

public class Main {
	private static void startWithSettings(String path) throws IOException {
		Settings s = Settings.getFromCfgFile(path);
		
		ForwardPair fp = s.getForward();
		
		Executor exec = Executors.newSingleThreadExecutor(); // page 119
		TaskScheduler scheduler = new TaskScheduler(10);
		ProxyFactory proxyFactory = ProxyFactory.forProxyType(s.getType(), fp.getDstAddr());
		AsyncServer server = new AsyncServer(scheduler, proxyFactory,
				fp.getSrcAddr());

		exec.execute(server);
	}
	
	public static void main(String[] args) throws IOException {
		startWithSettings("proxy.cfg");
	}
}
